﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Kokomo.Environment
{
	/// <summary>
	/// Associates a view type with a viewmodel type.
	/// </summary>
	/// <remarks>
	/// See <see cref="AttributedViewTemplateSelector"/> for usage information.
	/// </remarks>
	/// <seealso cref="AttributedViewTemplateSelector"/>
	[AttributeUsage(AttributeTargets.Class)]
	public class ViewTypeAttribute : Attribute
	{
		/// <summary>
		/// Gets the view type.
		/// </summary>
		/// <value>A type assignable to <see cref="FrameworkElement"/> that provides the visual
		/// tree for displaying a viewmodel.</value>
		public Type ViewType { get; private set; }

		/// <summary>
		/// Initializes an instance of <see cref="ViewTypeAttribute"/>.
		/// </summary>
		/// <param name="viewType">A type assignable to <see cref="FrameworkElement"/> that provides the visual
		/// tree for displaying the viewmodel.</param>
		/// <exception cref="ArgumentNullException"><paramref name="viewType"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentException"><paramref name="viewType"/> is not assignable to <see cref="FrameworkElement"/>.</exception>
		public ViewTypeAttribute(Type viewType)
		{
			if (viewType == null) throw new ArgumentNullException("viewType");
			if (!typeof(FrameworkElement).IsAssignableFrom(viewType))
				throw new ArgumentException("viewType is not assignable to FrameworkElement.", "viewType");

			this.ViewType = viewType;
		}
	}
}
